package com.ildepinc.persistence.concretes.models;

import java.sql.Timestamp;
import java.util.HashMap;

import com.ildepinc.persistence.abstracts.TableGenericExpirable;
import com.ildepinc.persistence.enums.NewProgressiveMethod;
// You should customize this class
// depending on the database engine
// you want to use.
// This version is for Apache Derby
public class Locale extends TableGenericExpirable {

  // CREATE TABLE DEVSCHEMA.LOCALES (
  //   LANGUAGE_ID INT NOT NULL,
  //   COUNTRY_ID NOT NULL NOT NULL,
  //   CODE VARCHAR(25) NOT NULL,
  //   NAME VARCHAR(250),
  //   ACTIVE BOOLEAN NOT NULL,
  //   VALID_FROM TIMESTAMP NOT NULL,
  //   VALID_TO TIMESTAMP NOT NULL,
  //   CONSTRAINT LINKS_PK PRIMARY KEY (LANGUAGE_ID, COUNTRY_ID)
  // );

  private Long language_id;
  private Long country_id;
  private String code;
  private String name;

  public Locale() {
    this.clear();
  }

  public Locale(
    Long language_id, Long country_id, String code, String name,
    Boolean active, Timestamp validFrom, Timestamp validTo,
    String schema
  ) {
    this.clear();
    this.setDefaults(schema);
    this.language_id = language_id;
    this.country_id = country_id;
    this.code = code;
    this.name = name;
    this.setActive(active);
    this.setValidFrom(validFrom);
    this.setValidTo(validTo);
  }

  public Locale(String schema) {
    this.clear();
    this.setDefaults(schema);
  }

  public Long getLanguage_id() {
    return language_id;
  }

  public void setLanguage_id(Long language_id) {
    this.language_id = language_id;
  }

  public Long getCountry_id() {
    return country_id;
  }

  public void setCountry_id(Long country_id) {
    this.country_id = country_id;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  @Override
  public void setDefaults(String schema) {
    this.setSchema(schema);
    this.setTableName("LOCALES");
    String fullQualifiedName = this.getSchema() + "." + this.getTableName();
    this.setPrimaryKeys(new HashMap<String, Object>() {
      {
        put("LANGUAGE_ID", null);
        put("COUNTRY_ID", null);
      }
    });
    this.setPkSingleColumn(Boolean.valueOf(false));
    this.setPkAutoIncremental(Boolean.valueOf(false));
    this.setSqlCreateTable("CREATE TABLE " + fullQualifiedName
        + " ( LANGUAGE_ID INT NOT NULL, COUNTRY_ID INT NOT NULL,"
        + " CODE VARCHAR(25) NOT NULL," + " NAME VARCHAR(255), "
        + " ACTIVE BOOLEAN NOT NULL,"
        + " VALID_FROM TIMESTAMP NOT NULL," + " VALID_TO TIMESTAMP NOT NULL,"
        + " CONSTRAINT LOCALES_PK PRIMARY KEY (LANGUAGE_ID, COUNTRY_ID)"
        + " )");
    this.setSqlInsert("INSERT INTO " + fullQualifiedName
        + " ( LANGUAGE_ID, COUNTRY_ID, CODE, NAME,"
        + " ACTIVE, VALID_FROM, VALID_TO )"
        + " VALUES ( ?, ?, ?, ?, ?, ?, ? )");
    this.setSqlUpdate("UPDATE " + fullQualifiedName
      + " SET CODE = ?, NAME = ?,"
      + " ACTIVE=?, VALID_FROM=?, VALID_TO=?");
    this.setSqlSelect("SELECT * FROM " + fullQualifiedName);
    this.setSqlDelete("DELETE FROM " + fullQualifiedName);
    this.setNewProgressiveMethod(NewProgressiveMethod.NONE);
  }

  @Override
  public void clear() {
    super.clear();
    this.language_id = null;
    this.country_id = null;
    this.code = null;
    this.name = null;
  }

}
